package com.crazy.exception;

/**
 * @author panyonghui
 * @describe 异常处理基类
 * @date 2022/1/17 11:57
 */
public class CrException extends Exception {
    private String messageKey;
    private Object[] args;
    private String defaultMessage;
    private final String DEFAULT_MESSAGE_KEY = "unknown.error.code";

    public CrException(){
        this("", null, null);
    }

    public CrException(String messageKey){
        this(messageKey, null, null);
    }

    public CrException(String messageKey, Throwable t){
        this(messageKey, t, null);
    }

    public CrException(String messageKey, Object[] args){
        this(messageKey, null, args);
    }

    public CrException(Throwable t){
        this("", t, null);
    }

    public CrException(String messageKey, Throwable t, Object[] args){
        super(messageKey, t);
        if (messageKey != null && messageKey.trim().length() > 0){
            this.messageKey = messageKey;
        } else {
            this.messageKey = DEFAULT_MESSAGE_KEY;
        }
        this.args = args;
    }

    public String getMessageKey() {
        return messageKey;
    }

    public void setMessageKey(String messageKey) {
        this.messageKey = messageKey;
    }

    public Object[] getArgs() {
        return args;
    }

    public void setArgs(Object[] args) {
        this.args = args;
    }

    public String getDefaultMessage() {
        return defaultMessage;
    }

    public void setDefaultMessage(String defaultMessage) {
        this.defaultMessage = defaultMessage;
    }
}
